package aplicacion;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.apache.wicket.Component;
import org.apache.wicket.Page;
import org.apache.wicket.markup.html.WebPage;
import org.apache.wicket.markup.html.basic.Label;
import org.apache.wicket.markup.html.link.Link;
import org.apache.wicket.markup.html.list.ListItem;
import org.apache.wicket.markup.html.list.ListView;

public class Indice extends WebPage {
	private static final long serialVersionUID = 1L;
	
	public Indice() {
		this.add(
			listaDeIndices()
		);
	}

	private Component listaDeIndices() {
		Map<String, Class<? extends Page>> paginas = Aplicacion.getPaginas();
		List<String> source = new ArrayList<String>(paginas.keySet());
		return new ListView<String>("indices", source) {
			private static final long serialVersionUID = 1L;

			@Override
			protected void populateItem(ListItem<String> item) {
				final String pagina = item.getModelObject();
				
				Link<String> link = new Link<String>("pagina"){
					private static final long serialVersionUID = 1L;

					@Override
					public void onClick() {
						setResponsePage(Aplicacion.getPaginas().get(pagina));
					}
				};
				link.add(new Label("pagina_texto", item.getModelObject()));
				
				item.add(link);
			}
		};
	}
}